window.onload=function(){
    function cssProperty( attr ){

        var prefix = [ 'O', 'ms', 'Moz', 'Webkit' ],
            length = prefix.length,

            style = document.createElement( 'i' ).style;

        cssProperty =  function( attr ){

            if( attr in style ){

                return true;

            }

            attr = attr.replace( /^[a-z]/, function( val ){

                return val.toUpperCase();

            });

            var len = length;

            while( len-- ){

                if( prefix[ len ] + attr in style ){

                return true;

                }

            }

            return false;

        };

    return cssProperty( attr );
    }
    if(cssProperty("animation")&&cssProperty("transition")&&window.Worker){
        $("#GG").css("display","none");
    }
    window.addEventListener("contextmenu",function(event){
        if(event.returnValue){
            event.returnValue=false;
        }else{
            event.preventDefault();
        }
    },false)

    function dl_go(){
        var UserId=$("#UserId").val();
        var Pwd=$("#Pwd").val();
        if(UserId==""){
            $("#UserId").css({"animation":"shake 0.8s","box-shadow":"0px 0px 4px 2px red"});
            setTimeout(()=>{
                $("#UserId").css("animation","none");
            },1000)
            return false;
        }
        if(Pwd==""){
            $("#Pwd").css({"animation":"shake 0.8s","box-shadow":"0px 0px 4px 2px red"});
            setTimeout(()=>{
                $("#Pwd").css("animation","none");
            },1000)
            return false;
        }
        $("#loginBoxBack").css("display","block")
        $.ajax({
            url:window.Api.login,
            type:"POST",
            data:{UserId:UserId,Pwd:Pwd},
            success:function(data){
                $("#loginBoxBack").css("display","none")
                if(data.State!=1000){
                    alert(data.Msg)
                }else{
                    sessionStorage.setItem("Tonken",data.Msg.RandCode);
                    // sessionStorage.setItem("ws",data.Msg.Gate);
                    sessionStorage.setItem("ws","192.168.1.181:29702");
                    sessionStorage.setItem("UserId",UserId);
                    openUserGG();
                }
            },
            error:function(data){
                $("#loginBoxBack").css("display","none")
                alert("登陆失败，网络错误")
            }
        })
    }
    // 登陆
    $("#Dl").click(dl_go)
    // 输入验证
    $(window).keydown(function(event){
        if(event.which==13){
            dl_go();
        }
    }) 
    $("#UserId").keydown(function(){
        $(this).css("box-shadow","none")
    })
    $("#Pwd").keydown(function(){
        $(this).css("box-shadow","none")
    })
    // LOGO动画
    var canvas=document.getElementById("canvas").getContext("2d");
    var img=new Image();
    img.src="";
    img.onload=function(){
        canvas.drawImage(img,-90,0);
        var xx=0;
        setInterval(function(){
            if(xx>90){
                xx=-90
            }else{
               xx++;  
            }
            canvas.clearRect(0,0,140,140);
            canvas.drawImage(img,xx,0);
        },10)
    }
    document.addEventListener('DOMContentLoaded', function (event) {
        // chrome 浏览器直接加上下面这个样式就行了，但是ff不识别
        document.body.style.zoom = 'reset';
        document.addEventListener('keydown', function (event) {
            if ((event.ctrlKey === true || event.metaKey === true)
            && (event.which === 61 || event.which === 107
                || event.which === 173 || event.which === 109
                || event.which === 187  || event.which === 189))
                {
                   event.preventDefault();
                }
        }, false);
        document.addEventListener('mousewheel DOMMouseScroll', function (event) {
            if (event.ctrlKey === true || event.metaKey) {
                event.preventDefault();
            }
        }, false);
    }, false);
    var animationEnd = (function(el) {
    var animations = {
        animation: 'animationend',
        OAnimation: 'oAnimationEnd',
        MozAnimation: 'mozAnimationEnd',
        WebkitAnimation: 'webkitAnimationEnd',
    };

    for (var t in animations) {
        if (el.style[t] !== undefined) {
        return animations[t];
        }
    }
    })(document.createElement('div'));

    $('.boxtab').eq(0).attr("class","boxtab animated2 bounceInLeft")
    $('.boxtab').eq(0).one(animationEnd, function(){
        $('.boxtab').eq(1).attr("class","boxtab animated2 bounceInLeft")
    });
    $('.boxtab').eq(1).one(animationEnd, function(){
        $('.boxtab').eq(2).attr("class","boxtab animated2 bounceInLeft")
    });
    $('.boxtab').eq(2).one(animationEnd, function(){
        $('.boxtab').eq(3).attr("class","boxtab animated2 bounceInLeft")
    });
    $('.boxtab').eq(3).one(animationEnd, function(){
        $('.conter').attr("class","conter animated tada")
    });

    var a=new Image();
    a.src="./static/img/fb4f10dac339607a456b9b9bf23c3b3e.jpg";
    var b=new Image();
    b.src="./static/img/ba01b0a82f2fcef612346f0cdfffe50e.jpg";
    var c=new Image();
    c.src="./static/img/85c4ae30fdeea704c8d41f56632aa4a7.png";
    var d=new Image();
    d.src="./static/img/f4d4596234bcb860203612d07fcdd239.png";   
    var f=new Image();
    f.src="./static/img/a9cc408bb2510a82f9ef5ca079b5948e.png";  
}
function openUserGG(){
    var a= $("#UsrGG").css("display");
    if(a=="none"){
        $("#UsrGG").css("display","block");
    }else{
        $("#UsrGG").css("display","none");
        sessionStorage.clear()
    }
}